home *** CD-ROM | disk | FTP | other *** search
- /* bioscom.c --- p556 */
- #include <stdio.h >
- #include <bios.h>
- #define COM1 0 /* Change this to 1 for COM2 */
- #define COM_INIT 0
- #define COM_SEND 1
- #define COM_RECEIVE 2
- #define COM_STATUS 3
- #define KEYBRD_READ 0
- #define KEYBRD_READY 1
- main()
- {
- int c;
- unsigned service, data, status;
- data = (0x03 | 0x00 |0x00 | 0x40);
- bioscom(COM_INIT,data, COM1);
- printf("Connecting to serial port 1. Type 'q' to exit\n");
- while(1)
- {
- /* First see if "DATA READY" flag is set. If yes read
- * character from serial port. */
- status =0x100 &
- bioscom(COM_STATUS, 0, COM1);
- if( status == 0x100)
- {
- /* If there is a character, get it and display it */
- c =0xff &
- bioscom(COM_RECEIVE, 0, COM1);
- printf("%c", c);
- }
- /* Now check if any key has been pressed */
- if(bioskey(KEYBRD_READY))
- {
- /* If yes,read the keyboard buffer */
- c = bioskey(KEYBRD_READ) & 0xff;
- if((c== 'q') || (c == 'Q'))
- {
- /* Exit if it's a 'q' or a 'Q'*/
- printf("Exiting...\n");
- exit(0);
- }
- /* Else, wait until "transmit holding register empty"
- * flag is set. Once it's set, send out character to
- * serial port. */
- status =0x2000 &
- bioscom(COM_STATUS, 0, COM1);
- while (status != 0x2000)
- {
- status = 0x2000 &
- bioscom(COM_STATUS, 0,COM1);
- }
- bioscom(COM_SEND, c, COM1);
- if(( status & 0x8000) == 0x8000)
- {
- printf("Error sending: %c\n", c);
- }
- }
- }
- }